<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="full-screen" content="yes">
    <meta name="x5-fullscreen" content="true">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
    <link rel="stylesheet" href="../../css/base.css">
    <link rel="stylesheet" href="../../css/pop-ups.css"><!--弹出层-->
    <link rel="stylesheet" href="../../css/icon-font.css"/><!--图标-->
    <link rel="stylesheet" href="../../css/comment.css"/>
    <link rel="stylesheet" href="../../css/report-list.css"/>
    <title>研报详情</title>
    <style>
        body {
            background-color: white;
        }

        .pd20 {
            padding: 0 0.4rem;
        }

        .report-detail-title {
            color: #222222;
        }

        .report-detail-character {
            margin: 0.24rem 0;
            color: rgba(34, 34, 34, 0.45);
        }

        .report-detail-datasource {
            color: #5273A6;
        }

        .report-detail-pdf {
            background-color: rgba(44, 104, 255, 0.05);
            padding: 0.16rem 0.24rem;
        }

        .report-detail-pdf img {
            height: 0.52rem;
            width: 0.52rem;
        }

        .report-detail-pdf-title {
            width: 5.5rem;
            margin-left: 0.18rem;
            margin-right: .3rem;
        }

        .report-detail-pdf-read {
            color: #2C68FF;
            margin-top: 0.04rem;
            margin-left: 0.18rem;
        }

        .report-detail-pdf-sum {
            background-color: #F7F7F7;
            padding: 0.4rem 0.24rem;
        }

        .report-detail-pdf-icon {
            color: #E5E5E5;
            top: 0.1rem;
            left: 0.15rem;
        }

        .report-detail-pdf-content {
            z-index: 2;
            color: rgba(34, 34, 34, 0.7);
            line-height: 0.6rem;
        }

        .report-detail-mzsm {
            color: #99A1B0;
            line-height: 0.36rem;
        }

        .report-detail-divide {
            width: 7.5rem;
            background-color: #F7F7F7;
            height: 0.16rem;
            margin: 0.72rem 0 0.4rem 0;
        }

        .report-detail-list {
            max-height: 15rem;
        }

        .p4 {
            padding: 0 0.4rem;
        }

        .p4:first-child {
            color: #222222;
            margin-bottom: 0.04rem;
        }

        .report-detail-split {
            width: 7.5rem;
            height: 1px;
            background: #F2F2F2;
        }

        .index-report-list-item:last-child {
            border: none;
        }

    </style>
</head>
<body>

<div class="report-detail-wrap flex-column ff400 h-100-p">
    <!--状态栏-->
    <div class="placeholder-top">
        <!--状态栏-->
        <div class="bg-main status-bar"></div>
        <!--导航栏-->
        <div class="bg-main nav-bar flex-row justify-content-between c-white align-items-center">
            <div class="left-bar" onclick="goBack()">
                <span class="iconfont iconfanhui1 fs16"></span>
            </div>
            <div class="center-bar fs16 ff500 line1"></div>
            <div class="flex-row">
                <div class="flex-row justify-content-center right-bar-mult">
                    <!--<span class="report-detail-sc iconfont iconshoucang1 fs16"></span>-->
                    <!--<span class="report-detail-sc iconfont iconshoucang fs16" style="color:#2C68F5;display:none"></span>-->
                </div>
                <!--<div class="flex-row justify-content-center right-bar-mult" onclick="dealShare()">-->
                <!--    <span class="iconfont iconfenxiang1 fs16"></span>-->
                <!--</div>-->
            </div>
        </div>
    </div>

    <div class="flex-1" style="overflow: hidden">
        <div class="h-100-p scoll-area scoll-y">
            <div class="pd20">
                <div class="report-detail-title ff600 fs22"></div>
                <div class="report-detail-character fs13 ff400 flex-row justify-content-between">
                    <div>来源：<span class="report-detail-datasource"></span></div>
                    <span></span>

                </div>
                <!--展示pdf部分-->
                <div class="flex-row align-items-center report-detail-pdf">
                    <div><img src="../../images/research/pdf2.png"></div>
                    <div class="flex-column ml5">
                        <div class="fs15 c-222 line1 report-detail-pdf-title"></div>
                        <div class="report-detail-pdf-read fs12">阅读原文</div>
                    </div>

                </div>

                <!--研报摘要部分-->
                <div class="report-detail-pdf-sum mt30 pos-r">
                    <span class="report-detail-pdf-icon iconfont iconzhaiyao fs34 pos-a"></span>
                    <div class="fs16 pos-r report-detail-pdf-content"></div>
                </div>


                <div class="report-detail-mzsm fs12 mb10 mt20">免责声明：文章内容仅供参考，不构成投资建议。投资者据此操作，风险自担。文章部分内容来自网络，如有涉及侵权烦请联系JT²智管有方资讯部责任编辑，我们将第一时间处理。</div>

            </div>
            <div class="report-detail-divide"></div>
            <div class="report-detail-list-wrap p4">
                <div class="fs18 ff600">延伸阅读</div>
            </div>
            <div class="report-detail-list"></div>

            <div class="report-detail-split mt20"></div>
        </div>
    </div>

    <div class="comment-area">
    </div>

</div>


</body>
<!--这四个文件的引入必须按照顺序-->
<script src="../../js/dict.js"></script>
<script src="../../js/jquery-3.4.1.min.js"></script>
<script src="../../js/checkJsBridge.js"></script>
<script src="../../js/utils.js"></script>
<script src="../../js/api.js"></script>
<!--这四个文件的引入必须按照顺序-->
<script src="../../js/date.js"></script>
<script src="../../js/icon-font.js"></script><!--用于彩色字体图标-->
<script src="../../js/template.js"></script>
<script>
  let pm = {
    infoId: '',
    infoType: '',
    pageNum: 1,
    pageSize: 5,
    isScroll: false,
    isCollect: 0,
    isThumb: 0,
    commentCnt: 0,
    thumbsupCnt: 0,
    datasource: '2',
    isLogin: false
  }

  function initPage(params) {
    //状态栏自适应
    Utils.sbhAdaptive()
    pm.infoId = params.infoId
    pm.infoType = params.infoType
    pm.isLogin = !user.isGuest
    //获取明细
    getFileDetail()  // 查询资讯明细
    getExtended()// 获取延伸阅读
    // findCollectStatus() // 查询收藏状态
    pageScroll()

    $('.report-detail-share').html(Template.share())
  }

  function reLoadPage() {
    pm.isLogin = !user.isGuest
    // 查询资讯明细
    getFileDetail()
    // 获取延伸阅读
    getExtended()
    // 查询收藏状态
    // findCollectStatus()
    $('.report-detail-share').html(Template.share())

  }

  function startPage(params) {

    $('.readCnt_' + params.infoId).html(params.readCnt)
    $('.commentCnt_' + params.infoId).html(params.commentCnt)

    pm.isLogin = !user.isGuest
    getCommentInfo()
  }

  function goBack() {
    jsBridge.goBack({
      infoId: pm.infoId,
      commentCnt: pm.commentCnt ? pm.commentCnt : 0,
      readCnt: pm.readCnt ? pm.readCnt : 0
    })
  }

  function getFileDetail() {
    Server.reportDetail.getFileDetail({//获取研报明细
      infoId: pm.infoId
    }).then(function success(data) {
      pm.commentCnt = data.commentCnt
      pm.thumbsupCnt = data.thumbsupCnt
      pm.readCnt = data.readCnt
      $('.comment-area').html(Template.commentDetail(pm.commentCnt, pm.thumbsupCnt))
      pm.title = data.title
      queryThumbStauts() // 查看点赞状态
      $('.report-detail-character').find('span').eq(0).text(data.dataSourceName)
      $('.report-detail-character').find('span').eq(1).text(DateUtils.int2TimeDesc(data.issuerDttm))
      $('.report-detail-title').html(data.title)
      $('.report-detail-pdf-title').html(data.title)
      if (data.trialContent) {
        $('.report-detail-pdf-content').html(data.trialContent)
      } else {
        $('.report-detail-pdf-sum').hide()
      }

      $('.report-detail-pdf').click(function () {
        openPdf(data.fileUrl, data.title)
      })

    }).catch(function (reason) {

    })
  }

  // 延伸阅读
  function getExtended() {
    Server.reportDetail.getInfoListForResearch({
      pageNum: pm.pageNum,
      pageSize: pm.pageSize,
      infoType: '8'
    }).then(function success(data) {
      let num = 0
      let htmlStr = ''
      $.each(data.infoListForResearchs, function (i, item) {
        num++
        htmlStr += Template.reportList(item)
      })
      if (num > 0) {
        $('.report-detail-list').html(htmlStr)
      } else {
        $('.report-detail-list-wrap').hide()
        $('.report-detail-divide').hide()
      }

      if (data.infoListSearch && data.infoListSearch.length >= pm.pageSize) {
        pm.isScroll = true
      } else {
        pm.isScroll = false
      }
    })
  }


  //收藏状态
  function findCollectStatus() {
    Server.reportDetail.findCollectStatus({
      collectionObjectId: pm.infoId,
      objectSource: pm.infoType,
    }).then(function (data) {
      //如果data._code大于0則說明已收藏
      if (data.isCollect > 0) {
        pm.isCollect = 1
        $('.report-detail-sc').toggle()
      }
    })
  }

  //点击收藏
  function judgeOrCollect() { //修改收藏的状态
    if (pm.isLogin) {
      $('.report-detail-sc').toggle()
      pm.isCollect = pm.isCollect === 1 ? 0 : 1
      Server.reportDetail.addOrModifyCollectionInfo({
        collectionObjectId: pm.infoId,
        objectSource: pm.infoType,
        datasource: pm.datasource,
        status: pm.isCollect,
      }).then(function (data) {
        // 弹出收藏、取消收藏成功
        if (data.code === 0) {
          jsBridge.callBridge('toast', {msg: (pm.isCollect === 1 ? '收藏成功' : '取消收藏成功')})
        }
      })
    } else {
      Utils.goLogin()
    }
  }


  //查看点赞状态
  function queryThumbStauts() {
    Server.reportDetail.queryThumbStauts({
      thumbupObjectId: pm.infoId,
      status: 1,
    }).then(function (data) {
      if (data.isThumb > 0) {
        pm.isThumb = 1
        $('.report-detail-wrap .comment-thumbsup-icon').addClass('comment-thumbsup-c')
      }
    })
  }

  // 点赞研报
  function goThumb() {
    if (pm.isLogin) {
      if (pm.isThumb === 1) { // 如果是取消点赞
        pm.isThumb = 0
        $('.report-detail-wrap .comment-thumbsup-icon').removeClass('comment-thumbsup-c')
        pm.thumbsupCnt = pm.thumbsupCnt === 1 ? '' : (pm.thumbsupCnt - 1)
        $('.report-detail-wrap .comment-thumbsup-cnt').text(pm.thumbsupCnt)

      } else {// 如果是点赞
        pm.isThumb = 1
        $('.report-detail-wrap .comment-thumbsup-icon').addClass('comment-thumbsup-c')
        pm.thumbsupCnt = pm.thumbsupCnt ? (pm.thumbsupCnt + 1) : 1
        $('.report-detail-wrap .comment-thumbsup-cnt').text(pm.thumbsupCnt)
      }
      Server.reportDetail.updateThumbsupInfo({
        thumbupObjectId: pm.infoId,
        objectSource: pm.infoType,
        datasource: pm.datasource, // 1、ios 2、安卓
        status: pm.isThumb
      }).then(function (data) {
        if (data.code === 0) {
          jsBridge.callBridge('toast', {msg: (pm.isThumb === 1 ? '点赞成功' : '取消点赞成功')})
        }
      })
    } else {
      Utils.goLogin()
    }
  }

  function showInput(v) {
    if (v === 0) {//取消发布
      $('.comment-show').hide()
    } else if (v === 1) { //发布评论
      if (Utils.emojiJudge($('.report-detail-wrap .comment-content').val())){
        // 不允许输入表情
        jsBridge.callBridge('toast', {msg: '请勿输入表情'})
        return
      }else if ($('.report-detail-wrap .comment-content').val() && $('.report-detail-wrap .comment-content').val().trim()) {//如果有内容，则添加评论
        addCommentInfo()
        showInput(0)
      } else {//弹出内容不能为空
        jsBridge.callBridge('toast', {msg: '评论不能为空'})
      }
    }
  }

  // 添加评论
  function addCommentInfo() {
    Server.reportDetail.addCommentInfo({
      commentObjectId: pm.infoId,
      objectSource: pm.infoType,
      datasource: pm.datasource,
      content: $('.report-detail-wrap .comment-content').val(),
    }).then(function (data) {
      if (data.code === 0) {
        jsBridge.callBridge('toast', {msg: '评论成功'})
        $('.report-detail-wrap .comment-content').val('')
        // 跳转到评论列表
        goComment()
      }
    })
  }

  // 加载评论列表
  function goComment() {
    goCommentList({infoId: pm.infoId, infoType: pm.infoType})
  }

  function writeComment() {
    if (pm.isLogin) {
      $('.comment-show').show()
      $('.comment-content').focus()
    } else {
      Utils.goLogin()
    }
  }

  // 获取评论数点赞数
  function getCommentInfo() {
    Server.reportDetail.getCommentInfo({
      infoId: pm.infoId
    }).then(function (data) {
      pm.commentCnt = data.commentCount
      pm.thumbsupCnt = data.thumbCount
      $('.comment-area').html(Template.commentDetail(pm.commentCnt, pm.thumbsupCnt))
      queryThumbStauts() // 查看点赞状态
    })
  }


  //处理状态栏滚动效果
  function dealHead(scrollTop) {
    let currStop
    if (scrollTop < 64) {
      currStop = scrollTop
      $('.center-bar').html('')
      $('.left-bar').css({
        'color': 'rgb(34,34,34)'
      })
    } else {
      currStop = 64
      $('.center-bar').html(pm.title)
      $('.left-bar').css({
        'color': 'rgba(34, 34, 34, ' + currStop / 64 + ')'
      })
    }
    $('.placeholder-top').css({
      'background': 'rgba(255, 255, 255, ' + currStop / 64 + ')'
    })

  }

  /**
   * @param callback 翻页回调函数
   */
  function pageScroll() {
    $('.scoll-area').scroll(function () {
      //需要特殊处理的滚动区域，需要放在scroller元素区域内
      let scrollTop = $(this).scrollTop()
      dealHead(scrollTop)
    })
  }


</script>
</html>
